import {Modal} from 'antd';
import {WeaSearchGroup, WeaDropdown,WeaTag, WeaFormItem} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

//用于获取高级搜索中的表单控件
export const getSearchs = (form, datas, needTigger = true, col=1,ecId) => {
  const {isFormInit} = form;
  let group = [];

  isFormInit && datas && datas.map((c,i) =>{
    let items = [];
    c.items.map(fields => {
      items.push({
        com:(<WeaFormItem ecId={`${ecId}_WeaFormItem@b4q0ec@${fields.domkey[0]}`}
          label={`${fields.label}`}
          labelCol={{span: 6}}
          wrapperCol={{span: 14}}>
          <WeaSwitch ecId={`${ecId}_WeaSwitch@15n0b6@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={form.getFormParams()}/>
        </WeaFormItem>),
        colSpan:1
      })
    });
    if(needTigger){
      group.push(<WeaSearchGroup ecId={`${ecId}_WeaSearchGroup@uii93e@bl${i}`} col={col} needTigger={needTigger} title={c.title} showGroup={c.defaultshow} items={items}/>)
    }else {
      group.push(<WeaSearchGroup ecId={`${ecId}_WeaSearchGroup@ntaf1n@b${i}}`} col={col} needTigger={needTigger} showGroup={c.defaultshow} items={items}/>)
    }
  });
  return group;
}

//后台配置共享新建
export const getFormBlogShare = (form, datas, needTigger = true) => {
  const {isFormInit} = form;
  let group = [];
  isFormInit && datas && datas.map((c,i) =>{
    let items = [];
    c.items.map(fields => {
     if(fields.domkey[0]!='isShowBlogPage'){
        items.push({
          com:(
            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@44ya2f@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: 14}}
              error={form.getError(fields)}
              tipPosition="bottom"
            >
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@u1ovb9@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={form.getFormParams()}/>
            </WeaFormItem>),
          colSpan:1
        })
     }
    });
    if(needTigger){
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@tsljvb@blo${i}er`} col={1} needTigger={needTigger} title={c.title} showGroup={c.defaultshow} items={items}/>)
    }else {
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@y6ohwx@blo${i}`} col={1} needTigger={needTigger} showGroup={c.defaultshow} items={items}/>)
    }
  });
  return group;
}


//带表单验证的form数据
export const getFormSearchs = (form, datas, needTigger = true,ecId) => {
  const {isFormInit} = form;
  let group = [];
  isFormInit && datas && datas.map((c,i) =>{
    let items = [];
    c.items.map(fields => {
      items.push({
        com:(
          <WeaFormItem ecId={`${ecId}_WeaFormItem@8ysfly@${fields.domkey[0]}`}
            label={`${fields.label}`}
            labelCol={{span: `${fields.labelcol}`}}
            wrapperCol={{span: 14}}
            error={form.getError(fields)}
            tipPosition="bottom"
          >
            <WeaSwitch ecId={`${ecId}_WeaSwitch@875fca@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={form.getFormParams()}/>
          </WeaFormItem>),
        colSpan:1
      })
    });
    if(needTigger){
      group.push(<WeaSearchGroup ecId={`${ecId}_WeaSearchGroup@j10siv@blogneedT${i}`} col={1} needTigger={needTigger} title={c.title} showGroup={c.defaultshow} items={items}/>)
    }else {
      group.push(<WeaSearchGroup ecId={`${ecId}_WeaSearchGroup@cu8k1u@blogne${i}`} col={1} needTigger={needTigger} showGroup={c.defaultshow} items={items}/>)
    }
  });
  return group;
}

//form重置
export const doFormReset = (form, conditioninfo) => {
  if(form && conditioninfo){
    form.resetForm();
    form.initFormFields(conditioninfo);
  }
}

//删除等信息确认
export const doConfirm = (content, func) => {//确认信息， 方法， 方法参数
  Modal.confirm({
    title: `${getLabel(131329,'信息确认')}`,
    content: content,
    okText: `${getLabel(382958,'确定')}`,
    cancelText:`${getLabel(31129,'取消')}`,
    onOk: () => func && func(),
  })
}

//提示
export const setModal = (content) => {
  Modal.warning({
    title: `${getLabel(15172,'系统提示')}`,
    content: content,
  });
}

//selectedRows遍历得到ids
export const getIds = (datas) => {
  let ids = [];
  datas && datas.length !== 0 && datas.map(item => {
    ids.push(Number(item.id))
  })
  return ids.join(',')
}

export const  onCheck = (form, func) => {
  form.validateForm().then(f=>{
    if(f.isValid){
      func && func()
    }else{
      f.showErrors();
    }
  });
}